package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.core.util.ValidGroup;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.mall.api.entity.MallAdvertisingTypeModel;
import com.mallcloud.mall.mall.service.MallAdvertisingTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "mall-广告位类型")
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/advertisingType")
public class MallAdvertisingTypeController {
	private final MallAdvertisingTypeService advertisingTypeService;

	@ApiOperation("分页")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('mall_advertisingtype_view')")
	public R<IPage<MallAdvertisingTypeModel>> page(Page page, MallAdvertisingTypeModel advertisingTypeModel) {
		return R.ok(advertisingTypeService.page(page, Wrappers.query(advertisingTypeModel)));
	}

	@ApiOperation("列表")
	@GetMapping("/list")
	@PreAuthorize("@pms.hasPermission('mall_advertisingtype_view')")
	public R<List<MallAdvertisingTypeModel>> list(MallAdvertisingTypeModel advertisingTypeModel) {
		return R.ok(advertisingTypeService.list(Wrappers.query(advertisingTypeModel)));
	}

	@ApiOperation("查询详情")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('mall_advertisingtype_view')")
	public R<MallAdvertisingTypeModel> getById(@PathVariable("id") Long id) {
		return R.ok(advertisingTypeService.getById(id));
	}

	@ApiOperation("新增")
	@PostMapping("/save")
	@PreAuthorize("@pms.hasPermission('mall_advertisingtype_add')")
	public R<Boolean> save(@RequestBody MallAdvertisingTypeModel advertisingTypeModel) {
		return R.ok(advertisingTypeService.save(advertisingTypeModel));
	}

	@ApiOperation("修改")
	@PostMapping("/update")
	@PreAuthorize("@pms.hasPermission('mall_advertisingtype_edit')")
	public R<Boolean> updateById(@Validated({ValidGroup.Update.class }) @RequestBody MallAdvertisingTypeModel advertisingTypeModel) {
		return R.ok(advertisingTypeService.updateById(advertisingTypeModel));
	}

	@ApiOperation("删除")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('mall_advertisingtype_del')")
	public R<Boolean> removeById(@PathVariable String id) {
		return R.ok(advertisingTypeService.removeById(id));
	}

	@ApiOperation("导出")
	@ResponseExcel
	@GetMapping("/export")
	@PreAuthorize("@pms.hasPermission('mall_advertisingtype_export')")
	public List<MallAdvertisingTypeModel> export(MallAdvertisingTypeModel advertisingTypeModel) {
		return advertisingTypeService.list(Wrappers.query(advertisingTypeModel));
	}
}
